<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="#0A5AF9">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" href="../css/aui.css" />
    <link rel="stylesheet" href="../css/mui.css" />
    <link rel="stylesheet" href="../css/public-head.css" />
    <link rel="stylesheet" type="text/css" href="../css/Coupon.css"/>
</head>

<body>
    <div class="mui-content coupon">
        <div id="nearby" class="mui-segmented-control mui-segmented-control mui-segmented-control-inverted">
            <a class="mui-control-item mui-active" href="#store1" id="Wash">洗车券</a>
            <a class="mui-control-item " href="#store2" id="Cash">代金券</a>
        </div>
        <div id="Pons">
          <div class="developed">
  					<img class="developed_img" src="../image/icon/wuyouhuiq@2x.png" alt="">
  					<span class="developed_span">
  						此处空空如也...
  					</span>
  				</div>
            <!--<div id="store1" class="mui-slider-item mui-control-content mui-active">
	           <div><img src="../image/icon/xicheq@2x.png" />
	                <div class="sto1-s"><span>2018.11.30-2018.12.29</span></div>
	                <div>去使用</div>
	            </div>
	            <div><img src="../image/icon/xicheq@2x.png" />
	                <div class="sto1-s"><span>2018.11.30-2018.12.29</span></div>
	                <div>去使用</div>
	            </div>
	            <div><img src="../image/icon/xicheq@2x.png" />
	                <div class="sto1-s"><span>2018.11.30-2018.12.29</span></div>
	                <div>去使用</div>
	            </div>
	        </div>
	        <div id="store2" class="mui-slider-item mui-control-content ">
	           <div>
	                <img src="../image/icon/daijinq@2x.png" />
	                <div>去使用</div>
	            </div>
	            <div><img src="../image/icon/daijinq2@2x.png" />
	                <div>去使用</div>
	            </div>
	            <div><img src="../image/icon/daijinq3@2x.png" />
	                <div>去使用</div>
	            </div>
	        </div>-->
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/public-head.js"></script>
<script type="text/javascript" src="../script/mui.js"></script>
<script type="text/javascript" src="../script/aui-tab.js"></script>
<script type="text/javascript" src="../script/aui-slide.js"></script>
<script type="text/javascript" src="../script/rem.js"></script>
<script src="../script/template-web.js"></script>
<!--获取洗车券列表模型-->
<script type="text/html" id="coupons">
    <!--洗车券-->
    <div id="store1" class="mui-slider-item mui-control-content mui-active">
      {{each data as val}}
      {{if val.is_voucher==1}}
        <div tapmode onclick="To_useimg({{val}})">
          <img src="{{val.image}}" />
            <div class="sto1-s"><span>2018.11.30-2018.12.29</span></div>
            <div>去使用</div>
        </div>
    {{/if}}
    {{/each}}
  </div>
    <!--代金券-->
    <div id="store2" class="mui-slider-item mui-control-content ">
      {{each data as val}}
      {{if val.is_voucher==0}}
        <div tapmode onclick="To_useimg({{val}})">
            <img src="{{val.image}}" />
            <div>去使用</div>
        </div>
    {{/if}}
    {{/each}}
  </div>
</script>
<script type="text/javascript">
var ProjectId;
    apiready = function() {
        init();
        if(api.pageParam.ProjectId==undefined){
          ProjectId=0;
        }else{
          ProjectId=api.pageParam.ProjectId;
        }
        // 获取优惠券列表
        fnCoupon()
    };
    headInner({
            title: "优惠券",
            //headleft
            headl: '<a href="#" style="color:white" class="mui-icon mui-icon-left-nav" tapmode onclick="api.closeWin()"></a>',
            //headright
            headr: '<a style="color:white"></a>',
            color: "", //默认是蓝色
            padding: "0px 0px 0px",
        })
        //获取优惠券列表
    function fnCoupon() {
        console.log(1231234123);
        console.log(ProjectId);
        BASE.MYajax({
            'pathName': 'coupon/index', //请求路径
            'methods': 'get',
            'ajaxData': {
                values:{
                	project_id:ProjectId
                }
            },
            'method': couponData //调用函数
        });
    }
    function couponData(ret, err) {
        if (ret.code == 200) {
            var j=0,k=0;
            for(var i=0;i<ret.data.length;i++){
              if(ret.data[i].is_voucher){
                // 洗车券(免费)
                j+=1
              }else if(ret.data[i].is_voucher==0){
                // 代金券(优惠)
                k+=1;
              }
            }
            if (ret.data.length>0) {
              console.log(k);
              console.log(j);
              $api.byId('Wash').innerHTML="洗车券("+j+")";
              $api.byId('Cash').innerHTML="代金券("+k+")";
              //渲染洗车券代金券列表
              var couponHtml = template("coupons", ret);
              document.getElementById('Pons').innerHTML = couponHtml;
            }

        } else {
            reToast(ret, err)
        }
    }

    // 使用优惠券
    function To_useimg(item) {
      if(ProjectId==0){
        api.openWin({
            name: 'order-details_1',
            url: '../html/order-details_1.html',
            pageParam:{
              pid:2
            }
        });
      }else{
        console.log(JSON.stringify(item));
        $api.setStorage('Discount_infor', item);
        // 远程调用方法
        api.execScript({
          name: 'order-details_1',
          script: 'use_discount();'
        });
        api.closeWin();
      }
    }

    function mine_2() {
        api.openWin({
            name: 'mine_2',
            url: '../html/mine_2.html'
        });
    }
</script>

</html>
